package A一周刷爆LeetCode.A基础班.I暴力递归;

/**
 * @author wei.zhao
 * @description: 汉诺塔问题
 * @date 2022年04月14日 10:45
 */
public class Code01_Hanoi {

    public static void main(String[] args) {
        hanoi(8);
    }

    public static void hanoi(int n) {
        fun(n, n, "from", "mid", "to");
    }

    /**
     * left：剩下待移动的圆盘个数
     * down：最底下的圆盘值
     */
    private static void fun(int left, int down, String from, String mid, String to) {
        if (left == 1) {
            System.out.println("将" + down + "从" + from + "移动到" + to);
        }   else {
            fun(left - 1, down - 1, from, to, mid);
            fun(1, down, from, mid, to);
            fun(left - 1, down - 1, mid, from, to);
        }
    }

}
